unit fCustomerManage;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, SpTBXDkPanels, TB2Item, TB2ExtItems,SpTBXItem, SpTBXTabs,fCustomerInfo,
  VirtualTrees, TB2Dock, TB2Toolbar, StdCtrls, TntStdCtrls, SpTBXEditors,SpTBXControls,
  uDAScriptingProvider, uDADataTable, uDAMemDataTable,fClientDataModule,
  {RemObjects:}SofitSystemLibrary_intf, DataAbstract4_Intf, uDARemoteDataAdapter;

type
  TCustomerNodeData = record
    Text: WideString;
end;
type PCustomerNodeData = ^TCustomerNodeData;

type
  TfmCustomerManage = class(TForm)
    pnlLeft: TPanel;
    SpTBXSplitter1: TSpTBXSplitter;
    pnlMain: TPanel;
    SpTBXTabSet1: TSpTBXTabSet;
    SpTBXTabItem1: TSpTBXTabItem;
    SpTBXTabItem2: TSpTBXTabItem;
    SpTBXTabItem3: TSpTBXTabItem;
    vstCustomer: TVirtualStringTree;
    SpTBXComboBox1: TSpTBXComboBox;
    SpTBXDock1: TSpTBXDock;
    SpTBXToolbar1: TSpTBXToolbar;
    TBControlItem1: TTBControlItem;
    SpTBXToolbar2: TSpTBXToolbar;
    SpTBXEdit1: TSpTBXEdit;
    TBControlItem2: TTBControlItem;
    tblCustomer: TDAMemDataTable;
    procedure FormDestroy(Sender: TObject);
    procedure SpTBXTabItem3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure vstCustomerInitNode(Sender: TBaseVirtualTree; ParentNode,
      Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
    procedure vstCustomerGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
      Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
    procedure vstCustomerFocusChanged(Sender: TBaseVirtualTree;
      Node: PVirtualNode; Column: TColumnIndex);
  private
    { Private declarations }
    FCustomerInfoView: TfmCustomerInfo;
  public
    { Public declarations }
  end;

var
  fmCustomerManage: TfmCustomerManage;

implementation

{$R *.dfm}

procedure TfmCustomerManage.FormCreate(Sender: TObject);
begin
  vstCustomer.Align := alClient;
  vstCustomer.NodeDataSize := SizeOf(TCustomerNodeData);
  tblCustomer.Open;
  tblCustomer.First;
  vstCustomer.RootNodeCount := tblCustomer.RecordCount;
end;

procedure TfmCustomerManage.FormDestroy(Sender: TObject);
begin
  if not (FCustomerInfoView = nil) then
    FreeAndNil(FCustomerInfoView);
end;

procedure TfmCustomerManage.SpTBXTabItem3Click(Sender: TObject);
begin
  if FCustomerInfoView = nil then
  begin
    FCustomerInfoView := TfmCustomerInfo.Create(pnlMain);
    FCustomerInfoView.BorderStyle := bsNone;
    FCustomerInfoView.Parent := pnlMain;
    FCustomerInfoView.Align := alClient;
    FCustomerInfoView.Visible := True;
  end;
end;

procedure TfmCustomerManage.vstCustomerFocusChanged(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Column: TColumnIndex);
var
  nd: PCustomerNodeData;
begin
  nd := Sender.GetNodeData(Node);
  FCustomerInfoView.m_no := nd^.Text;
  FCustomerInfoView.ShowData;
end;

procedure TfmCustomerManage.vstCustomerGetText(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
  var CellText: WideString);
var
  nd: PCustomerNodeData;
begin
  nd := Sender.GetNodeData(Node);
  CellText := nd^.Text;
end;

procedure TfmCustomerManage.vstCustomerInitNode(Sender: TBaseVirtualTree; ParentNode,
  Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
var
  nd: PCustomerNodeData;
begin
  nd := Sender.GetNodeData(Node);
  nd^.Text := tblCustomer.FieldByName('bc_no').AsWideString;
  tblCustomer.Next;
end;

end.
